Alignmnent and counting of the fastq files

This step is performed on the O2 cluster. The fastq file quality was checked using FastQC and MultiQC. They are aligned to Ensembl mm10 genome and counted using Salmon pseudoaligner. Output sf files were transfered from O2 to local machine for further processing in R.

Library loading and set up

library(DESeq2)
library(limma)
library(tximport)
library(gridExtra)
library(ensembldb)
library(EnsDb.Mmusculus.v79)
library(grid)
library(ggplot2)
library(lattice)
library(reshape)
library(mixOmics)
library(gplots)
library(RColorBrewer)
library(readr)
library(dplyr)
library(VennDiagram)
library(clusterProfiler)
library(DOSE)
library(org.Mm.eg.db)
library(pathview)
library(AnnotationDbi)
library(gtools)
library(enrichplot)

Compile gene count files in DESeq2

Set working directory to the folder that contains only gene count txt files

# Generate a tx2gene object for matrix generation
edb <- EnsDb.Mmusculus.v79 
transcriptsID <- as.data.frame(transcripts(edb))
tx2gene <- as.data.frame(cbind(transcriptsID$tx_id, transcriptsID$gene_id))

# Generate DESeqData using the counting result generated using Salmon
setwd("/Users/mizuhi/OneDrive - Harvard University/Haigis Lab/Projects/Halo-Ago2/Halo-Ago-KRas/Raw Data/RNA-Seq/Mouse colon tumor/4-OHT enema model/Gene Counts")
inDir = getwd()
countFiles = list.files(inDir, pattern=".sf$", full.names = TRUE)
basename(countFiles)
##  [1] "AV1_LIB038588_GEN00143059_R1.sf"  "AV2_LIB038588_GEN00143060_R1.sf" 
##  [3] "AV3_LIB038588_GEN00143061_R1.sf"  "AV4_LIB038588_GEN00143062_R1.sf" 
##  [5] "AV5_LIB041682_GEN00156282_R1.sf"  "AV6_LIB041682_GEN00156283_R1.sf" 
##  [7] "AV7_LIB041682_GEN00156284_R1.sf"  "AV8_LIB041682_GEN00156285_R1.sf" 
##  [9] "AVK1_LIB038588_GEN00143063_R1.sf" "AVK2_LIB038588_GEN00143064_R1.sf"
## [11] "AVK3_LIB038588_GEN00143065_R1.sf" "AVK4_LIB038588_GEN00143066_R1.sf"
## [13] "AVK5_LIB041682_GEN00156286_R1.sf" "AVK6_LIB041682_GEN00156287_R1.sf"
## [15] "AVK7_LIB041682_GEN00156288_R1.sf" "AVK8_LIB041682_GEN00156289_R1.sf"
names(countFiles) <- c('KrasWT_1','KrasWT_2','KrasWT_3','KrasWT_4','KrasWT_5','KrasWT_6','KrasWT_7','KrasWT_8','KrasG12D_1','KrasG12D_2','KrasG12D_3','KrasG12D_4','KrasG12D_5','KrasG12D_6','KrasG12D_7','KrasG12D_8')

txi.salmon <- tximport(countFiles, type = "salmon", tx2gene = tx2gene, ignoreTxVersion = TRUE)
## reading in files with read_tsv
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 
## transcripts missing from tx2gene: 27668
## summarizing abundance
## summarizing counts
## summarizing length
DESeqsampletable <- data.frame(condition = c('control','control','control','control','control','control','control','control','experimental','experimental','experimental','experimental','experimental','experimental','experimental','experimental'))

DESeqsampletable$batch <- factor(c('1','1','1','1','2','2','2','2','1','1','1','1','2','2','2','2'))
DESeqsampletable$gender <- factor(c('F', 'F', 'M', 'M', 'M', 'F', 'M', 'M', 'F', 'M', 'M', 'F', 'M', 'M', 'F', 'M'))

rownames(DESeqsampletable) <- colnames(txi.salmon$counts)

ddsHTSeq<- DESeqDataSetFromTximport(txi.salmon, DESeqsampletable, ~condition + batch + gender)
## Warning in DESeqDataSet(se, design = design, ignoreRank): some variables in
## design formula are characters, converting to factors
## using counts and average transcript lengths from tximport
ddsHTSeq_norm <- estimateSizeFactors(ddsHTSeq)
## using 'avgTxLength' from assays(dds), correcting for library size
ddsHTSeq_norm <- DESeq(ddsHTSeq_norm)
## using pre-existing normalization factors
## estimating dispersions
## gene-wise dispersion estimates
## mean-dispersion relationship
## final dispersion estimates
## fitting model and testing
ddsHTSeq_analysis <- results(ddsHTSeq_norm, contrast = c("condition", "experimental", "control"))
ddsHTSeq_analysis <- lfcShrink(ddsHTSeq_norm, contrast = c("condition", "experimental", "control"), res = ddsHTSeq_analysis, type = "normal")
## using 'normal' for LFC shrinkage, the Normal prior from Love et al (2014).
## 
## Note that type='apeglm' and type='ashr' have shown to have less bias than type='normal'.
## See ?lfcShrink for more details on shrinkage type, and the DESeq2 vignette.
## Reference: https://doi.org/10.1093/bioinformatics/bty895

MA plot was generated to inspect the correct shrinkage of LFC.

DESeq2::plotMA(ddsHTSeq_analysis)

Quality Inspection of the Gene Count Data

Generate raw count table that contains the simple counts of each gene

Data is transformed and pseudocount is calculated.

setwd("/Users/mizuhi/OneDrive - Harvard University/Haigis Lab/Projects/Halo-Ago2/Halo-Ago-KRas/Raw Data/RNA-Seq/Mouse colon tumor/4-OHT enema model/Analysis")
dir.create("PDF_figure", showWarnings = FALSE)
rawCountTable <- as.data.frame(counts(ddsHTSeq_norm, normalized = TRUE))
pseudoCount = log2(rawCountTable + 1)
grid.arrange(
  ggplot(pseudoCount, aes(x= KrasWT_1)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasWT_1"), 
  ggplot(pseudoCount, aes(x= KrasWT_2)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasWT_2"),
  ggplot(pseudoCount, aes(x= KrasWT_3)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasWT_3"),   ggplot(pseudoCount, aes(x= KrasWT_4)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasWT_4"),   ggplot(pseudoCount, aes(x= KrasWT_5)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasWT_5"), 
  ggplot(pseudoCount, aes(x= KrasWT_6)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasWT_6"),
  ggplot(pseudoCount, aes(x= KrasWT_7)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasWT_7"),   ggplot(pseudoCount, aes(x= KrasWT_8)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasWT_8"), nrow = 2)

grid.arrange(
  ggplot(pseudoCount, aes(x= KrasG12D_1)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasG12D_1"),
  ggplot(pseudoCount, aes(x= KrasG12D_2)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasG12D_2"),
  ggplot(pseudoCount, aes(x= KrasG12D_3)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasG12D_3"), 
  ggplot(pseudoCount, aes(x= KrasG12D_4)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasG12D_4"),
  ggplot(pseudoCount, aes(x= KrasG12D_5)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasG12D_5"),
  ggplot(pseudoCount, aes(x= KrasG12D_6)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasG12D_6"),
  ggplot(pseudoCount, aes(x= KrasG12D_7)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasG12D_7"), 
  ggplot(pseudoCount, aes(x= KrasG12D_8)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasG12D_8"), nrow = 2)

pdf('PDF_figure/QC_histogram.pdf',
    width = 14,
    height = 7)
grid.arrange(
  ggplot(pseudoCount, aes(x= KrasWT_1)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasWT_1"), 
  ggplot(pseudoCount, aes(x= KrasWT_2)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasWT_2"),
  ggplot(pseudoCount, aes(x= KrasWT_3)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasWT_3"),   ggplot(pseudoCount, aes(x= KrasWT_4)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasWT_4"),   ggplot(pseudoCount, aes(x= KrasWT_5)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasWT_5"), 
  ggplot(pseudoCount, aes(x= KrasWT_6)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasWT_6"),
  ggplot(pseudoCount, aes(x= KrasWT_7)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasWT_7"),   ggplot(pseudoCount, aes(x= KrasWT_8)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasWT_8"), nrow = 2)
  
grid.arrange(
  ggplot(pseudoCount, aes(x= KrasG12D_1)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasG12D_1"),
  ggplot(pseudoCount, aes(x= KrasG12D_2)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasG12D_2"),
  ggplot(pseudoCount, aes(x= KrasG12D_3)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasG12D_3"), 
  ggplot(pseudoCount, aes(x= KrasG12D_4)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasG12D_4"),
  ggplot(pseudoCount, aes(x= KrasG12D_5)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasG12D_5"),
  ggplot(pseudoCount, aes(x= KrasG12D_6)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasG12D_6"),
  ggplot(pseudoCount, aes(x= KrasG12D_7)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasG12D_7"), 
  ggplot(pseudoCount, aes(x= KrasG12D_8)) + xlab(expression(log[2](count + 1))) + ylab("Number of Genes") + 
    geom_histogram(colour = "white", fill = "#525252", binwidth = 0.6) + labs(title = "KrasG12D_8"), nrow = 2)
dev.off()
## quartz_off_screen 
##                 2

Between-sample distribution

Check on the gene count distribution across all genes.

#Boxplots
suppressMessages(df <- melt(pseudoCount, variable_name = "Samples"))
df <- data.frame(df, Condition = substr(df$Samples,1,7))

ggplot(df, aes(x=Samples, y=value, fill = Condition)) + geom_boxplot() + xlab("") + 
  ylab(expression(log[2](count+1))) + scale_fill_manual(values = c("#619CFF", "#F564E3")) + theme(axis.text.x = element_text(angle = 90, hjust = 1))

pdf('PDF_figure/QC_boxplot.pdf',
    width = 8,
    height = 5)
ggplot(df, aes(x=Samples, y=value, fill = Condition)) + geom_boxplot() + xlab("") + 
  ylab(expression(log[2](count+1))) + scale_fill_manual(values = c("#619CFF", "#F564E3")) + theme(axis.text.x = element_text(angle = 90, hjust = 1))
dev.off()
## quartz_off_screen 
##                 2
#Histograms and density plots
ggplot(df, aes(x=value, colour = Samples, fill = Samples)) + ylim(c(0, 0.25)) + 
  geom_density(alpha = 0.2, size = 1.25) + facet_wrap(~ Condition) +
  theme(legend.position = "top") + xlab(expression(log[2](count+1)))

pdf('PDF_figure/QC_densityplot.pdf',
    width = 8,
    height = 5)
ggplot(df, aes(x=value, colour = Samples, fill = Samples)) + ylim(c(0, 0.25)) + 
  geom_density(alpha = 0.2, size = 1.25) + facet_wrap(~ Condition) +
  theme(legend.position = "top") + xlab(expression(log[2](count+1)))
dev.off()
## quartz_off_screen 
##                 2

Generate MA plots

MA plots are used to check for imbalance in sequencing depth between samples of the same condition. I did not generate MA plot for all library pairs. But the example pairs I selected show that there are imbalance in sequencing depth, but the imbalance is quite random and this is common in RNA-Seq datasets.

## WT1 vs WT2
x = pseudoCount[, 1]
y = pseudoCount[, 2]
## M-values
M = x - y
## A-values
A = (x + y)/2
df = data.frame(A, M)

suppressWarnings(
ggplot(df, aes(x = A, y = M)) + geom_point(size = 1.5, alpha = 1/5) +
  geom_hline(color = "blue3", yintercept = 0) + stat_smooth(se = FALSE, method = "loess", color = "red3") + labs(title = "KrasWT_1 vs KrasWT_2"))
## `geom_smooth()` using formula 'y ~ x'

## WT1 vs WT3
x = pseudoCount[, 1]
y = pseudoCount[, 3]
## M-values
M = x - y
## A-values
A = (x + y)/2
df = data.frame(A, M)

suppressWarnings(
ggplot(df, aes(x = A, y = M)) + geom_point(size = 1.5, alpha = 1/5) +
  geom_hline(color = "blue3", yintercept = 0) + stat_smooth(se = FALSE, method = "loess", color = "red3") + labs(title = "KrasWT_1 vs KrasWT_3"))
## `geom_smooth()` using formula 'y ~ x'

## WT1 vs WT5
x = pseudoCount[, 1]
y = pseudoCount[, 5]
## M-values
M = x - y
## A-values
A = (x + y)/2
df = data.frame(A, M)

suppressWarnings(
ggplot(df, aes(x = A, y = M)) + geom_point(size = 1.5, alpha = 1/5) +
  geom_hline(color = "blue3", yintercept = 0) + stat_smooth(se = FALSE, method = "loess", color = "red3") + labs(title = "KrasWT_1 vs KrasWT_5"))
## `geom_smooth()` using formula 'y ~ x'

## WT1 vs WT6
x = pseudoCount[, 1]
y = pseudoCount[, 6]
## M-values
M = x - y
## A-values
A = (x + y)/2
df = data.frame(A, M)

suppressWarnings(
ggplot(df, aes(x = A, y = M)) + geom_point(size = 1.5, alpha = 1/5) +
  geom_hline(color = "blue3", yintercept = 0) + stat_smooth(se = FALSE, method = "loess", color = "red3") + labs(title = "KrasWT_1 vs KrasWT_6"))
## `geom_smooth()` using formula 'y ~ x'

## G12D_1 vs G12D_2
x = pseudoCount[, 9]
y = pseudoCount[, 10]
## M-values
M = x - y
## A-values
A = (x + y)/2
df = data.frame(A, M)

suppressWarnings(
ggplot(df, aes(x = A, y = M)) + geom_point(size = 1.5, alpha = 1/5) +
  geom_hline(color = "blue3", yintercept = 0) + stat_smooth(se = FALSE, method = "loess", color = "red3") + labs(title = "KrasG12D_1 vs KrasG12D_2"))
## `geom_smooth()` using formula 'y ~ x'

## G12D_1 vs G12D_3
x = pseudoCount[, 9]
y = pseudoCount[, 11]
## M-values
M = x - y
## A-values
A = (x + y)/2
df = data.frame(A, M)

suppressWarnings(
ggplot(df, aes(x = A, y = M)) + geom_point(size = 1.5, alpha = 1/5) +
  geom_hline(color = "blue3", yintercept = 0) + stat_smooth(se = FALSE, method = "loess", color = "red3") + labs(title = "KrasG12D_1 vs KrasG12D_3"))
## `geom_smooth()` using formula 'y ~ x'

## G12D_1 vs G12D_5
x = pseudoCount[, 9]
y = pseudoCount[, 13]
## M-values
M = x - y
## A-values
A = (x + y)/2
df = data.frame(A, M)

suppressWarnings(
ggplot(df, aes(x = A, y = M)) + geom_point(size = 1.5, alpha = 1/5) +
  geom_hline(color = "blue3", yintercept = 0) + stat_smooth(se = FALSE, method = "loess", color = "red3") + labs(title = "KrasG12D_1 vs KrasG12D_5"))
## `geom_smooth()` using formula 'y ~ x'

## G12D_1 vs G12D_6
x = pseudoCount[, 9]
y = pseudoCount[, 14]
## M-values
M = x - y
## A-values
A = (x + y)/2
df = data.frame(A, M)

suppressWarnings(
ggplot(df, aes(x = A, y = M)) + geom_point(size = 1.5, alpha = 1/5) +
  geom_hline(color = "blue3", yintercept = 0) + stat_smooth(se = FALSE, method = "loess", color = "red3") + labs(title = "KrasG12D_1 vs KrasG12D_6"))
## `geom_smooth()` using formula 'y ~ x'

Clustering of the sample-to-sample distances

This is the sanity check step to confirm that under a un-supervised clustering, WT and G12D samples will cluster together. For some reason, the code is giving error when try to plot this heatmap in RStudio, so I created a pdf file that contains the heatmap in the Analysis folder named Hierchical Clustering.pdf

ddsHTSeq_transform <- varianceStabilizingTransformation(ddsHTSeq)
## using 'avgTxLength' from assays(dds), correcting for library size
assay(ddsHTSeq_transform) <- limma::removeBatchEffect(assay(ddsHTSeq_transform), ddsHTSeq_transform$batch)
rawCountTable_transform <- as.data.frame(assay(ddsHTSeq_transform))
pseudoCount_transform = log2(rawCountTable_transform + 1)
mat.dist = pseudoCount_transform
mat.dist = as.matrix(dist(t(mat.dist)))
mat.dist = mat.dist/max(mat.dist)
setwd("/Users/mizuhi/OneDrive - Harvard University/Haigis Lab/Projects/Halo-Ago2/Halo-Ago-KRas/Raw Data/RNA-Seq/Mouse colon tumor/4-OHT enema model/Analysis")
png('Hierchical_Clustering_filtered.png')
cim(mat.dist, symkey = FALSE, margins = c(6, 6))
suppressMessages(dev.off())
## quartz_off_screen 
##                 2
pdf('PDF_figure/Hierchical_Clustering.pdf',
    width = 6,
    height = 6)
cim(mat.dist, symkey = FALSE, margins = c(6, 6))
dev.off()
## quartz_off_screen 
##                 2

Final output is following: Hierchical Clustering

Principal component plot of the samples

I performed PCA analysis on all datasets to confirm that samples from the same condition group together. This step has to be performed using varianceStabelizingTransformed dataset, so that the high variance in genes with low counts will not skew the data.

The top 500 most variable genes are selected for PCA analysis.

plotPCA(ddsHTSeq_transform, intgroup = "condition", ntop = 500) +
  geom_text(aes(label=name), vjust = 2, hjust = -0.1) +
  xlim(-30,40) + ylim(-30,20)

pdf('PDF_figure/PCA.pdf',
    width = 8,
    height = 5)
plotPCA(ddsHTSeq_transform, intgroup = "condition", ntop = 500) +
  geom_text(aes(label=name), vjust = 2, hjust = -0.1) +
  xlim(-30,40) + ylim(-30,20)
dev.off()
## quartz_off_screen 
##                 2

Raw data filtering and Generate the raw count file with all detected genes

This step removes all genes with 0 counts across all samples, output a csv file and also generate a density plot using filtered dataset.

keep <- rowMeans(rawCountTable[,1:6]) > 50 | rowMeans(rawCountTable[,7:12]) > 50
filterCount <- pseudoCount[keep,]
df <- melt(filterCount, variable_name = "Samples")
## Using  as id variables
df <- data.frame(df, Condition = substr(df$Samples,1,7))
detected_raw_count_norm <- rawCountTable[keep,]
write.csv(detected_raw_count_norm, "normalized_raw_gene_counts_filtered.csv")

ggplot(df, aes(x=value, colour = Samples, fill = Samples)) + 
  geom_density(alpha = 0.2, size = 1.25) + facet_wrap(~ Condition) +
  theme(legend.position = "top") + xlab("pseudocounts")

pdf('PDF_figure/QC_filtered_densityplot.pdf',
    width = 8,
    height = 5)
ggplot(df, aes(x=value, colour = Samples, fill = Samples)) + 
  geom_density(alpha = 0.2, size = 1.25) + facet_wrap(~ Condition) +
  theme(legend.position = "top") + xlab("pseudocounts")
dev.off()
## quartz_off_screen 
##                 2

Generate file with differential analysis result

This step generates the analysis file that contains results from differential analysis.

write.csv(as.data.frame(ddsHTSeq_analysis[keep,]), "Differential Analysis_filtered.csv")

Draw heatmap for transcripts that are significantly dysregulated in KRasG12D samples

Genes that were not detected were removed from the list. Genes with padj < 0.05 were considered significantly dysregulated. Their normalized counts were z-scored and used for plotting the heatmap.

suppressMessages(library(mosaic))

rawCountTable_transform_detected <- rawCountTable_transform[keep,]
dif_analysis <- as.data.frame(ddsHTSeq_analysis)[keep,]
sig_dif <- subset(dif_analysis, dif_analysis$padj < 0.05)
sig_index <- c()
for (i in 1:dim(sig_dif)[1]) {
  sig_index <- c(sig_index ,grep(rownames(sig_dif)[i], rownames(rawCountTable_transform_detected)))
}
sig_count <- rawCountTable_transform_detected[sig_index,]
sig_dif <- cbind(sig_dif, sig_count)
for (i in 1:dim(sig_dif)[1]) {
  sig_dif[i,7:22] <- zscore(as.numeric(sig_dif[i,7:22]))
}

my_palette <- colorRampPalette(c("blue", "white", "red"))(256)
heatmap_matrix <- as.matrix(sig_dif[,7:22])

png('G12D vs WT 4OHT enema colon tumor RNASeq.png',
    width = 300,
    height = 600,
    res = 100,
    pointsize = 8)
heatmap.2(heatmap_matrix,
          main = "G12D vs WT\n4OHT enema\nColon tumor RNASeq",
          density.info = "none",
          key = TRUE,
          lhei = c(1,7),
          col=my_palette,
          cexCol = 1,
          margins = c(8,2),
          trace = "none",
          dendrogram = "both",
          labRow = FALSE,
          keysize = 2,
          ylab = "Genes",
          Colv = "NA")
dev.off()
## quartz_off_screen 
##                 2
pdf('PDF_figure/Heatmap.pdf',
    width = 6,
    height = 12)
par(cex.main=1.1)
heatmap.2(heatmap_matrix,
          main = "G12D vs WT\n4OHT enema\nColon tumor RNASeq",
          density.info = "none",
          key = TRUE,
          lhei = c(1,7),
          col=my_palette,
          cexCol = 1,
          margins = c(8,2),
          trace = "none",
          dendrogram = "row",
          labRow = FALSE,
          keysize = 2,
          ylab = "Genes",
          Colv = "NA")
dev.off()
## quartz_off_screen 
##                 2

Final output is Heatmap for differential genes

Scatter plot, MA plot and Volcano plot for data visualization

# Scatter plot
detected_pseudocount <- pseudoCount[keep,]
dif_analysis$KrasG12D_mean <- rowMeans(detected_pseudocount[,9:16])
dif_analysis$KrasWT_mean <- rowMeans(detected_pseudocount[,1:8])
ggplot(dif_analysis, aes(x = KrasWT_mean, y = KrasG12D_mean)) +
  xlab("WT_Average(log2)") + ylab("G12D_Average(log2)") + 
  geom_point(data = dif_analysis, alpha = 0.5, size = 1, color = "grey") +
  geom_point(data = subset(dif_analysis, padj < 0.05 & log2FoldChange > 0), alpha = 0.5, size = 1, color = "red") +
  geom_point(data = subset(dif_analysis, padj < 0.05 & log2FoldChange < 0), alpha = 0.5, size = 1, color = "blue") +
  labs(title = "G12D vs WT Scatter Plot")

pdf('PDF_figure/Scatter_Plot.pdf',
    width = 5,
    height = 4)
ggplot(dif_analysis, aes(x = KrasWT_mean, y = KrasG12D_mean)) +
  xlab("WT_Average(log2)") + ylab("G12D_Average(log2)") + 
  geom_point(data = dif_analysis, alpha = 0.5, size = 1, color = "grey") +
  geom_point(data = subset(dif_analysis, padj < 0.05 & log2FoldChange > 0), alpha = 0.5, size = 1, color = "red") +
  geom_point(data = subset(dif_analysis, padj < 0.05 & log2FoldChange < 0), alpha = 0.5, size = 1, color = "blue") +
  labs(title = "G12D vs WT Scatter Plot")
dev.off()
## quartz_off_screen 
##                 2
# MA plot
ggplot(dif_analysis, aes(x = log(baseMean,2), y = log2FoldChange)) +
  xlab("Average Expression") + ylab("LFC") + 
  geom_point(data = dif_analysis, alpha = 0.5, size = 1, color = "grey") +
  geom_point(data = subset(dif_analysis, padj < 0.05 & log2FoldChange > 0), alpha = 0.5, size = 1, color = "red") +
  geom_point(data = subset(dif_analysis, padj < 0.05 & log2FoldChange < 0), alpha = 0.5, size = 1, color = "blue") +
labs(title = "WT vs G12D MA Plot")

pdf('PDF_figure/MA_Plot.pdf',
    width = 5,
    height = 4)
ggplot(dif_analysis, aes(x = log(baseMean,2), y = log2FoldChange)) +
  xlab("Average Expression") + ylab("LFC") + 
  geom_point(data = dif_analysis, alpha = 0.5, size = 1, color = "grey") +
  geom_point(data = subset(dif_analysis, padj < 0.05 & log2FoldChange > 0), alpha = 0.5, size = 1, color = "red") +
  geom_point(data = subset(dif_analysis, padj < 0.05 & log2FoldChange < 0), alpha = 0.5, size = 1, color = "blue") +
labs(title = "WT vs G12D MA Plot")
dev.off()
## quartz_off_screen 
##                 2
# Volcano Plot
ggplot(dif_analysis, aes(x = log2FoldChange, y = -log(pvalue,10))) +
  xlab("LFC") + ylab("-log10(P value)") + 
  geom_point(data = dif_analysis, alpha = 0.5, size = 1, color = "black") +
  geom_point(data = subset(dif_analysis, padj < 0.05 & log2FoldChange > 0), alpha = 0.5, size = 1, color = "red") +
  geom_point(data = subset(dif_analysis, padj < 0.05 & log2FoldChange < 0), alpha = 0.5, size = 1, color = "blue") +
  labs(title = "WT vs G12D Volcano Plot") +
  xlim(-2,2) +
  ylim(0,20)
## Warning: Removed 73 rows containing missing values (geom_point).

pdf('PDF_figure/Volcano_Plot.pdf',
    width = 5,
    height = 4)
ggplot(dif_analysis, aes(x = log2FoldChange, y = -log(pvalue,10))) +
  xlab("LFC") + ylab("-log10(P value)") + 
  geom_point(data = dif_analysis, alpha = 0.5, size = 1, color = "black") +
  geom_point(data = subset(dif_analysis, padj < 0.05 & log2FoldChange > 0), alpha = 0.5, size = 1, color = "red") +
  geom_point(data = subset(dif_analysis, padj < 0.05 & log2FoldChange < 0), alpha = 0.5, size = 1, color = "blue") +
  labs(title = "WT vs G12D Volcano Plot") +
  xlim(-2,2) +
  ylim(0,20)
## Warning: Removed 73 rows containing missing values (geom_point).
dev.off()
## quartz_off_screen 
##                 2

GO analysis for DE genes

Classic GO analysis is performed here for all DE genes detected in this dataset. The reference list is list of genes detected in RNASeq. Three categories of GO terms are tested here, including biological process, molecular function and cellular component.

target_gene <- as.character(rownames(sig_dif))
detected_gene <- as.character(rownames(detected_pseudocount))

# Run GO enrichment analysis for biological process
ego_BP <- enrichGO(gene = target_gene, 
                universe = detected_gene,
                keyType = "ENSEMBL",
                OrgDb = org.Mm.eg.db, 
                ont = "BP", 
                pAdjustMethod = "BH", 
                pvalueCutoff = 0.05, 
                readable = TRUE)

# Output results from GO analysis to a table
cluster_summary_BP <- data.frame(ego_BP)

write.csv(cluster_summary_BP, "GO/GO analysis_BP.csv")

# Run GO enrichment analysis for molecular function 
ego_MF <- enrichGO(gene = target_gene, 
                universe = detected_gene,
                keyType = "ENSEMBL",
                OrgDb = org.Mm.eg.db, 
                ont = "MF", 
                pAdjustMethod = "BH", 
                pvalueCutoff = 0.05, 
                readable = TRUE)

# Output results from GO analysis to a table
cluster_summary_MF <- data.frame(ego_MF)

write.csv(cluster_summary_MF, "GO/GO analysis_MF.csv")

# Run GO enrichment analysis for cellular component 
ego_CC <- enrichGO(gene = target_gene, 
                universe = detected_gene,
                keyType = "ENSEMBL",
                OrgDb = org.Mm.eg.db, 
                ont = "CC", 
                pAdjustMethod = "BH", 
                pvalueCutoff = 0.05, 
                readable = TRUE)

# Output results from GO analysis to a table
cluster_summary_CC <- data.frame(ego_CC)

write.csv(cluster_summary_CC, "GO/GO analysis_CC.csv")

Overlaping tumor transcriptomics and proteomics

The proteomics file that I am using here is generated by Joao, tissue collect done by Emily and differential analysis done by Doug. The raw quantification file is 2017-03-19_Haigis_5v5_Pro.csv. The differential analysis file is

proteomics_quant <- read_csv("/Users/mizuhi/OneDrive - Harvard University/Haigis Lab/Projects/Halo-Ago2/Halo-Ago-KRas/Raw Data/Proteomics data/colon tumor-enema model/2017-03-19_Haigis_5v5_Pro.csv")
proteomics_diff <- read_csv("/Users/mizuhi/OneDrive - Harvard University/Haigis Lab/Projects/Halo-Ago2/Halo-Ago-KRas/Raw Data/Proteomics data/colon tumor-enema model/crcMS_diff.csv")

This is to annotate the inputs in proteomics quantification file with their corresponding Ensembl ID.

Now I try to match Uniprot to Ensembl ID using EnsDb.Mmusculus.v79 package

# Return the Ensembl IDs for a set of genes
annotations_edb <- AnnotationDbi::select(EnsDb.Mmusculus.v79,
                                           keys = proteomics_quant$`Protein Id`,
                                           columns = c("GENEID", "GENENAME"),
                                           keytype = "UNIPROTID")

# Determine the indices for the non-duplicated genes
non_duplicates_idx <- which(duplicated(annotations_edb$UNIPROTID) == FALSE)
non_duplicates_idx <- which(duplicated(annotations_edb$GENEID) == FALSE)

# Return only the non-duplicated genes using indices
annotations_edb <- annotations_edb[non_duplicates_idx, ]

# Check number of NAs returned
is.na(annotations_edb$GENEID) %>%
  which() %>%
  length()
## [1] 0

I need to add the Ensembl ID to the proteomics quantification dataframe.

proteomics_quant <- as_tibble(proteomics_quant)
proteomics_diff <- as_tibble(proteomics_diff)
dif_analysis$GeneID <- rownames(dif_analysis)
dif_analysis_tib <- as_tibble(dif_analysis)
proteomics_quant <- inner_join(proteomics_quant, annotations_edb, by=c("Protein Id"="UNIPROTID"))
proteomics_diff <- inner_join(proteomics_diff, annotations_edb, by=c("Protein Id"="UNIPROTID"))

Then I overlap the Stable Gene IDs in Proteomics with the ones in detected in transcriptomics to find outputs that were detected in both large datasets. For the overlapped proteins, the log fold change for their transcript expression and protein expression were extracted for testing their correlation.

overlap <- intersect(rownames(detected_raw_count_norm), proteomics_quant$GENEID)
overlap_lfc <- inner_join(dif_analysis_tib[,c(2,9)], proteomics_diff[,c(7,8)], by=c("GeneID"="GENEID"))
colnames(overlap_lfc) <- c('rna_lfc', 'GeneID', 'protein_lfc')

# Plot scatterplot and calculate the Spearman Correlation
ggplot(overlap_lfc, aes(x = rna_lfc, y = protein_lfc)) +
  geom_point(data = overlap_lfc, alpha = 0.5, size = 1, color = "black") +
  xlab("RNA LFC (KRas/WT)") + ylab("Protein LFC (KRas/WT)") + 
  labs(title = "Correlation between proteomics and transcriptomics") +
  xlim(-3,3) + ylim(-3,3)
## Warning: Removed 4 rows containing missing values (geom_point).

pdf('PDF_figure/cor_RNA_protein.pdf',
    width = 5,
    height = 4)
ggplot(overlap_lfc, aes(x = rna_lfc, y = protein_lfc)) +
  geom_point(data = overlap_lfc, alpha = 0.5, size = 1, color = "black") +
  xlab("RNA LFC (KRas/WT)") + ylab("Protein LFC (KRas/WT)") + 
  labs(title = "Correlation between proteomics and transcriptomics") +
  xlim(-3,3) + ylim(-3,3)
## Warning: Removed 4 rows containing missing values (geom_point).
dev.off()
## quartz_off_screen 
##                 2
# Correlation test
cor.test(overlap_lfc$rna_lfc, overlap_lfc$protein_lfc)
## 
##  Pearson's product-moment correlation
## 
## data:  x and y
## t = 36.492, df = 7042, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.3789650 0.4182475
## sample estimates:
##       cor 
## 0.3987892

Zooming into genes/proteins that are dysregulated in transcriptomics and proteomics

This analysis is performed only on proteins that are detected in both datasets.

overlap_p <- inner_join(dif_analysis_tib[,c(6,9)], proteomics_diff[,c(4,5,8)], by=c("GeneID"="GENEID"))
colnames(overlap_p) <- c('rna_p', 'GeneID', 'protein_p', 'protein_q')

Making a Venn Diagram to show the overlap between DE genes and DE proteins

rna_de <- subset(overlap_p, overlap_p$rna_p < 0.05)$GeneID
protein_de <- subset(overlap_p, overlap_p$protein_p < 0.05 & overlap_p$protein_q < 0.1)$GeneID
overlap_de <- intersect(rna_de, protein_de)
grid.newpage()
draw.pairwise.venn(length(rna_de),
                   length(protein_de),
                   length(overlap_de),
                   catergory <- c("DE_Transcriptomics",
                                  "DE_Proteomics"),
                   lty = "blank",
                   ex.text = FALSE,
                   fill = c("pink", "lightblue"),
                   cat.pos = c(200, 135), cat.dist = 0.05, margin = 0.05,
                   fontfamily = "sans", cat.fontfamily = "sans")

## (polygon[GRID.polygon.3615], polygon[GRID.polygon.3616], polygon[GRID.polygon.3617], polygon[GRID.polygon.3618], text[GRID.text.3619], text[GRID.text.3620], lines[GRID.lines.3621], text[GRID.text.3622], lines[GRID.lines.3623], text[GRID.text.3624], text[GRID.text.3625])
pdf('PDF_figure/overlap_RNA_protein.pdf',
    width = 5,
    height = 4)
draw.pairwise.venn(length(rna_de),
                   length(protein_de),
                   length(overlap_de),
                   catergory <- c("DE_Transcriptomics",
                                  "DE_Proteomics"),
                   lty = "blank",
                   ex.text = FALSE,
                   fill = c("pink", "lightblue"),
                   cat.pos = c(200, 135), cat.dist = 0.05, margin = 0.05,
                   fontfamily = "sans", cat.fontfamily = "sans")
## (polygon[GRID.polygon.3626], polygon[GRID.polygon.3627], polygon[GRID.polygon.3628], polygon[GRID.polygon.3629], text[GRID.text.3630], text[GRID.text.3631], lines[GRID.lines.3632], text[GRID.text.3633], lines[GRID.lines.3634], text[GRID.text.3635], text[GRID.text.3636])
dev.off()
## quartz_off_screen 
##                 2